import java.sql.*;

/**
 * @Author admin
 * @Date 2019/4/24 9:04
 */
public class Test2 {
    public static void main(String[] args) {
        /*注册驱动
        * 获得数据库连接
        * 获得能操作SQL的对象
        * 执行SQL语句*/
        Connection conn=null;
        Statement stmt=null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url="jdbc:mysql://localhost:3306/zhm";
            String user="root";
            String password="123456";
            conn= DriverManager.getConnection(url,user,password);
            stmt=conn.createStatement();
            String sql="UPDATE`user`\n" +
                    "SET age=15\n" +
                    "WHERE NAME='lisi'";
            stmt.executeUpdate(sql);



        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (stmt!=null){
                try {
                    stmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (conn!=null){
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
